package com.gzxw.mogublog.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gzxw.mogublog.commons.entity.SysDicData;
import com.gzxw.mogublog.utils.R;
import com.gzxw.mogublog.xo.service.SysDicDataService;
import com.gzxw.mogublog.xo.vo.SysDictDataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sysDictData")
public class SysDictDataController {

    @Autowired
    private SysDicDataService sysDicDataService;

    @PostMapping("/getList")
    public R getList(@RequestBody SysDictDataVO sysDictDataVO) {

       IPage<SysDicData> pageList = sysDicDataService.getList(sysDictDataVO);
        HashMap<String, Object> map = new HashMap<>();
        map.put("records", pageList.getRecords());
        map.put("total", pageList.getTotal());
        map.put("size", pageList.getSize());
        map.put("current", pageList.getCurrent());
        return R.success("返回成功",map);
    }

    @PostMapping("/add")
    public R add(@RequestBody SysDictDataVO sysDictDataVO) {

       String message =  sysDicDataService.addSysDictData(sysDictDataVO);

       return R.success("200",message);
    }

    @PostMapping("/edit")
    public R edit(@RequestBody SysDictDataVO sysDictDataVO) {

        String message = sysDicDataService.editDicData(sysDictDataVO);

        return R.success("200",message);
    }

    // 批量删除字典数据
    @PostMapping("/deleteBatch")
    public R deleteBatch(@RequestBody List<SysDictDataVO> sysDictDataVOList) {

        String message = sysDicDataService.deleteBatch(sysDictDataVOList);

        return R.success("200",message);
    }

    // 根据字典类型获取字典数据
    @PostMapping("/getListByDictType")
    public R getListByDictType(String dictTypeUid) {

        Map<String, Object> listMap =sysDicDataService.getListByDictType(dictTypeUid);

        return R.success("200",listMap);
    }

    @PostMapping("/getListByDictTypeList")
    public R getListByDictTypeList(@RequestBody List<String> dictTypeList) {

        if (dictTypeList.size()<=0) {
            return R.success("200","操作失败");
        }
        Map<String ,Object> result = sysDicDataService.getListByDictTypeList(dictTypeList);
        return R.success("200",result);
    }
}
